package com.youku.plugins.Tips.view
{
   import flash.display.Sprite;
   import com.youku.interfaces.IPlayerProxy;
   import com.youku.plugins.PluginEventDispather;
   import flash.display.Shape;
   import flash.text.TextField;
   import com.youku.baseUI.BasePlayerButton;
   import com.youku.utils.AssetUtil;
   import flash.text.TextFormat;
   import com.youku.skin.YaheiFontManager;
   import flash.events.MouseEvent;
   import com.youku.plugins.Tips.TipsEvent;
   import flash.geom.Point;
   
   public class Tips extends Sprite
   {
      
      public function Tips(param1:String, param2:String, param3:IPlayerProxy, param4:PluginEventDispather = null) {
         super();
         this._playerProxy = param3;
         this._eventManager = param4;
         this._key = param1;
         this._text = param2;
         this.init();
         this.addEvent();
      }
      
      private var _playerProxy:IPlayerProxy;
      
      private var _eventManager:PluginEventDispather;
      
      private var _key:String;
      
      private var _text:String;
      
      private var _space:Number = 8;
      
      private var _background:Shape;
      
      private var _infoTF:TextField;
      
      private var _knowButton:Sprite;
      
      private var _closeButton:BasePlayerButton;
      
      private var _width:Number;
      
      private var _height:Number;
      
      private var _arrowWidth:Number = 10;
      
      private var _arrowHeight:Number = 10;
      
      private function init() : void {
         this._background = new Shape();
         addChild(this._background);
         this._infoTF = AssetUtil.getTextField(false);
         this._infoTF.defaultTextFormat = new TextFormat(YaheiFontManager.MICROSOFT_YAHEI,15,16777215);
         this._infoTF.text = this._text;
         this._infoTF.width = this._infoTF.textWidth + 4;
         this._infoTF.height = 24;
         this._infoTF.x = this._space;
         this._infoTF.y = this._space - 3;
         this._infoTF.selectable = false;
         addChild(this._infoTF);
         this._knowButton = new Sprite();
         this._knowButton.x = this._space;
         this._knowButton.y = 30;
         this._knowButton.mouseChildren = false;
         this._knowButton.buttonMode = true;
         addChild(this._knowButton);
         var _loc1_:TextField = AssetUtil.getTextField(false);
         _loc1_.defaultTextFormat = new TextFormat(YaheiFontManager.MICROSOFT_YAHEI,15,39372);
         _loc1_.text = "知道了";
         _loc1_.width = _loc1_.textWidth + 2;
         _loc1_.height = 24;
         _loc1_.selectable = false;
         this._knowButton.addChild(_loc1_);
         this._closeButton = AssetUtil.getStyleButton("P_CloseButton");
         AssetUtil.restoreButtonSize(this._closeButton);
         this._closeButton.x = this._space + this._infoTF.width + this._space * 1.5;
         this._closeButton.y = this._space;
         addChild(this._closeButton);
         this._width = this._closeButton.x + this._closeButton.width + this._space;
         this._height = this._knowButton.y + this._knowButton.height + this._space;
      }
      
      private function addEvent() : void {
         this._knowButton.addEventListener(MouseEvent.CLICK,this.onKnowClick);
         this._closeButton.addEventListener(MouseEvent.CLICK,this.onCloseClick);
      }
      
      private function onCloseClick(param1:MouseEvent) : void {
         this._eventManager.dispatchEvent(new TipsEvent(TipsEvent.CLOSE_CLICK,this._key));
      }
      
      private function onKnowClick(param1:MouseEvent) : void {
         this._eventManager.dispatchEvent(new TipsEvent(TipsEvent.KNOW_CLICK,this._key));
      }
      
      public function update(param1:Point, param2:Number) : void {
         var _loc3_:Number = this._width / 2;
         this.x = param1.x - this._width / 2;
         this.y = param1.y - this._height - this._arrowHeight;
         if(param1.x < this._width / 2 + this._space)
         {
            _loc3_ = param1.x - this._space;
            this.x = this._space;
         }
         if(param1.x > param2 - (this._width / 2 + this._space))
         {
            _loc3_ = this._width / 2 + (this._width / 2 + this._space - (param2 - param1.x));
            this.x = param2 - (this._width + this._space);
         }
         this._background.graphics.clear();
         this._background.graphics.lineStyle(0,6710886,1);
         this._background.graphics.beginFill(0,0.85);
         this._background.graphics.lineTo(0,0);
         this._background.graphics.lineTo(this._width,0);
         this._background.graphics.lineTo(this._width,this._height);
         this._background.graphics.lineTo(_loc3_ + this._arrowWidth,this._height);
         this._background.graphics.lineTo(_loc3_,this._height + this._arrowHeight);
         this._background.graphics.lineTo(_loc3_ - this._arrowWidth,this._height);
         this._background.graphics.lineTo(0,this._height);
         this._background.graphics.lineTo(0,0);
         this._background.graphics.endFill();
      }
   }
}
